import {
  Message
} from 'element-ui'
/**
 * 深拷贝
 *
 * @param obj - 目标对象
 * @returns {*}
 */

/* eslint-disable */
export const deepCopy = (obj) => {
  if (obj === null || typeof (obj) !== 'object') {
    return obj;
  }

  if ('isActiveClone' in obj) {
    throw new Error('循环引用警告⚠️');
  }

  let temp;
  if (obj instanceof Date) {
    temp = new obj.constructor();
  } else {
    temp = obj.constructor();
  }

  Object.keys(obj).forEach((key) => {
    obj.isActiveClone = null;
    temp[key] = deepCopy(obj[key]);
    delete obj.isActiveClone;
  });
  return temp;
};

// import {
//   BusinessError,
//   HttpBusinessError,
//   HttpSystemError,
//   HttpCancelError,
// } from 'webServiceV/base/Exception';

export const errorMessage = {
  show(error) {
    if (typeof error !== "object") {
      throw error;
    }

    if (error.name === "BusinessError") {
      // eslint-disable-next-line
      Message({
        type: "error",
        message:
          process.env.NODE_ENV === "pro"
            ? "系统出现错误，请稍后再重试"
            : error.message || error.message
      });
    } else if (
      error.name === "HttpBusinessError" ||
      error.name === "HttpSystemError"
    ) {
      // eslint-disable-next-line
      Message({
        type: "error",
        message: error.message || error.message
      });
    } else if (!(error.name === "HttpCancelError")) {
      // eslint-disable-next-line
      Message({
        type: "error",
        message:
          process.env.NODE_ENV === "pro"
            ? "系统出现错误"
            : error.message || error.message
      });
      // eslint-disable-next-line
      console.error(error);
    }
  }
};
